#import "DDQianBao.h"
@interface DDQianBao()
@property (nonatomic, strong) DDImageView *IMG;
@property (nonatomic, strong) CCLabel *label;
@end
@implementation DDQianBao
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.IMG.hidden = NO;
        self.bounds = CGRectMake(0, 0, self.label.bounds.size.width + self.label.bounds.size.height + 5, self.label.bounds.size.height);
    }
    return self;
}
- (CCLabel *)label
{
    if (!_label)
    {
        _label = [[CCLabel alloc] init];
        _label.font = FONT(UIFontWeightRegular, 15);
        _label.textColor = [DDHelper help].color;
        _label.text = @"优先钱包扣款";
        _label.backgroundColor = [UIColor clearColor];
        [self addSubview:_label];
        _label.c_right.c_equal(self);
        _label.c_centerY.c_equal(self);
    }
    return _label;
}
- (DDImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[DDImageView alloc] init];
        _IMG.imageName = @"selected";
        _IMG.layer.cornerRadius = self.label.bounds.size.height / 2.0;
        _IMG.layer.masksToBounds = YES;
        _IMG.backgroundColor = [DDHelper help].color;
        [self addSubview:_IMG];
        _IMG.c_right.c_equal(self.label.c_left).with.coffset(-5);
        _IMG.c_centerY.c_equal(self);
        _IMG.c_size.c_equal(CGSizeMake(self.label.bounds.size.height, self.label.bounds.size.height));
    }
    return _IMG;
}
- (void)setTitle:(NSString *)title
{
    if (_title != title)
    {
        _title = title;
        self.label.text = [NSString stringWithFormat:@"优先钱包扣款(余额:%@元)",_title];
        self.bounds = CGRectMake(0, 0, self.label.bounds.size.width + self.label.bounds.size.height + 5, self.label.bounds.size.height);
        self.label.c_size.c_equal(self.label.bounds.size);
        self.c_size.c_equal(self.bounds.size);
    }
}
- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    self.label.textColor = (self.selected)?[DDHelper help].color:TEXT_GRAY_COLOR;
    self.IMG.backgroundColor = (self.selected)?[DDHelper help].color:[UIColor clearColor];
    self.IMG.imageName = (self.selected)?@"selected":@"unselect";
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    self.label.alpha = 0.5;
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    self.label.alpha = 1.0;
}
@end
